<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 * Author: Lê Đặng Khánh Duy
 */
include_once LIBRARIES_TOOLS_XTEMPLATE;
include_once LIBRARIES_ENTITIES_DATABASE;
include_once LIBRARIES_ENTITIES_ARTICLES;
include_once LIBRARIES_TOOLS_UTILITY;

class ArticleController {

    public function invoke() {


       
        $dir = dirname(__FILE__);
        $xtemplate = new XTemplate($dir . DS . 'views' . DS . 'article.html');
        $articles = $this->getAriticleByIDCategory(209);
        
        if ($articles != null) {
            foreach ($articles as $article) {

                $xtemplate->assign('ARTICLE_DESCRIPTION', $article->getDescription());
                 $xtemplate->assign('ARTICLE_IMAGE', $article->getImage());
                $xtemplate->assign('ARTICLE_TITLE', $article->getTitle());
                $xtemplate->assign('ARTICLE_ALIAS', $article->getAlias());
                $xtemplate->parse("main.article");
            }
           
            

            
        }
        $xtemplate->parse("main");
            $xtemplate->out("main");
    }

    // tải danh sách ảnh theo mã gallery
    private function getAriticleByIDCategory($categoryID) {
        $db = new Database();
        try {
            $article = new Articles();
            $article->setCategoryID($categoryID);
            $articles=$article->getAriticleByIDCategory($db);
            $db->submitChanges();
            return $articles;
        } catch (PDOException $exc) {
            echo $exc->getMessage();
            $db->rollback();
            exit();
        }
    }

}

?>
